home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / eval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-02  |  3.8 KB  |  156 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: eval.c%v 3.38.2.78 1993/02/20 02:59:43 woo Exp woo $";
  3. #endif
  4.  
  5.  
  6. /* GNUPLOT - eval.c */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * Send your comments or suggestions to 
  35.  *  info-gnuplot@dartmouth.edu.
  36.  * This is a mailing list; to join it send a note to 
  37.  *  info-gnuplot-request@dartmouth.edu.  
  38.  * Send bug reports to
  39.  *  bug-gnuplot@dartmouth.edu.
  40.  */
  41.  
  42. #include <stdio.h>
  43. #include "plot.h"
  44.  
  45. extern int c_token;
  46. extern struct ft_entry ft[];
  47. extern struct udvt_entry *first_udv;
  48. extern struct udft_entry *first_udf;
  49. extern struct at_type at;
  50. extern struct lexical_unit token[];
  51.  
  52. struct value *Ginteger();
  53.  
  54.  
  55.  
  56. struct udvt_entry *
  57. add_udv(t_num)  /* find or add value and return pointer */
  58. int t_num;
  59. {
  60. register struct udvt_entry **udv_ptr = &first_udv;
  61.  
  62.     /* check if it's already in the table... */
  63.  
  64.     while (*udv_ptr) {
  65.         if (equals(t_num,(*udv_ptr)->udv_name))
  66.             return(*udv_ptr);
  67.         udv_ptr = &((*udv_ptr)->next_udv);
  68.     }
  69.  
  70.     *udv_ptr = (struct udvt_entry *)
  71.       alloc((unsigned long)sizeof(struct udvt_entry), "value");
  72.     (*udv_ptr)->next_udv = NULL;
  73.     copy_str((*udv_ptr)->udv_name,t_num);
  74.     (*udv_ptr)->udv_value.type = INTGR;    /* not necessary, but safe! */
  75.     (*udv_ptr)->udv_undef = TRUE;
  76.     return(*udv_ptr);
  77. }
  78.  
  79.  
  80. struct udft_entry *
  81. add_udf(t_num)  /* find or add function and return pointer */
  82. int t_num; /* index to token[] */
  83. {
  84. register struct udft_entry **udf_ptr = &first_udf;
  85.  
  86.     int i;
  87.     while (*udf_ptr) {
  88.         if (equals(t_num,(*udf_ptr)->udf_name))
  89.             return(*udf_ptr);
  90.         udf_ptr = &((*udf_ptr)->next_udf);
  91.     }
  92.      *udf_ptr = (struct udft_entry *)
  93.       alloc((unsigned long)sizeof(struct udft_entry), "function");
  94.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  95.     (*udf_ptr)->definition = NULL;
  96.     (*udf_ptr)->at = NULL;
  97.     copy_str((*udf_ptr)->udf_name,t_num);
  98.     for(i=0; i<MAX_NUM_VAR; i++)
  99.         (void) Ginteger(&((*udf_ptr)->dummy_values[i]), 0);
  100.     return(*udf_ptr);
  101. }
  102.  
  103.  
  104. union argument *
  105. add_action(sf_index)
  106. enum operators sf_index;        /* index of p-code function */
  107. {
  108.     if (at.a_count >= MAX_AT_LEN)
  109.         int_error("action table overflow",NO_CARET);
  110.     at.actions[at.a_count].index = sf_index;
  111.     return(&(at.actions[at.a_count++].arg));
  112. }
  113.  
  114.  
  115. int standard(t_num)  /* return standard function index or 0 */
  116. {
  117. register int i;
  118.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  119.         if (equals(t_num,ft[i].f_name))
  120.             return(i);
  121.     }
  122.     return(0);
  123. }
  124.  
  125.  
  126.  
  127. execute_at(at_ptr)
  128. struct at_type *at_ptr;
  129. {
  130. register int i,index,count,offset;
  131.  
  132.     count = at_ptr->a_count;
  133.     for (i = 0; i < count;) {
  134.         index = (int)at_ptr->actions[i].index;
  135.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  136.         if (is_jump(index))
  137.             i += offset;
  138.         else
  139.             i++;
  140.     }
  141. }
  142.  
  143. /*
  144.  
  145.  'ft' is a table containing C functions within this program. 
  146.  
  147.  An 'action_table' contains pointers to these functions and arguments to be
  148.  passed to them. 
  149.  
  150.  at_ptr is a pointer to the action table which must be executed (evaluated)
  151.  
  152.  so the iterated line exectues the function indexed by the at_ptr and 
  153.  passes the address of the argument which is pointed to by the arg_ptr 
  154.  
  155. */
  156.